<template>
  <div>
    <div style="margin:15px 0;">
      <span style="font-size:35px;font-weight:600;">资源管理</span>
    </div>
    <!-- <div style="margin:10px 0;">
      <span style="font-size:25px;">(上传文件的名字将会被展示在)</span>
    </div> -->
    <div>
      <div style="margin:15px 0;">
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="文件标题">
            <el-input class="ipt" placeholder="这是一个关于什么的文件......" maxlength="30" show-word-limit v-model="form.title">
            </el-input>
          </el-form-item>
        </el-form>
      </div>
      <div style="margin:10px 0;">
        <el-upload class="upload-demo" drag :auto-upload='false' action="#" multiple :on-change="changefile">
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          <div class="el-upload__tip" slot="tip"></div>
        </el-upload>
      </div>
      <div style="margin:10px 0;">
        <el-button slot="trigger" size="small" type="primary">上传</el-button>
      </div>
    </div>

    <div>
      <el-table :data="tableData.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase())
        || data.content.toLowerCase().includes(search.toLowerCase())
        || data.company.toLowerCase().includes(search.toLowerCase())
        || data.telephone.toLowerCase().includes(search.toLowerCase())
        || data.email.toLowerCase().includes(search.toLowerCase())
        )" style="width: 100%">
        <el-table-column label="日期" prop="updateTime">
        </el-table-column>
        <el-table-column label="姓名" prop="name">
        </el-table-column>
        <el-table-column label="公司" prop="company">
        </el-table-column>
        <el-table-column label="手机" prop="telephone">
        </el-table-column>
        <el-table-column label="邮箱" prop="email">
        </el-table-column>
        <el-table-column label="留言" prop="content">
        </el-table-column>
        <el-table-column align="right">
          <template slot="header" slot-scope="scope">
            <el-input v-model="search" size="mini" placeholder="输入关键字搜索" />
          </template>
          <template slot-scope="scope">
            <el-button size="small" disabled @click="handleEdit(scope.$index, scope.row)">查看</el-button>
            <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Source',
  data () {
    return {
      tableData: [],
      search: '',
      fileList: [],
      form: {
        title: ''
      }
    }
  },
  methods: {
    handleEdit (index, row) {
      console.log(index, row)
    },
    handleDelete (index, row) {
      console.log(index, row)
    },
    changefile (file, fileList) {
      this.fileList = fileList
      console.log(fileList)
    },
    getData () {
      this.$axios({
        method: 'get',
        url: '/words/select'
      }).then((res) => {
        this.tableData = res.data.data
      })
    }
  },
  mounted () {
    this.getData()
  }
}
</script>

<style scoped>
/* .ipt {
  width: 650px;
} */
.el-form-item {
  width: 700px;
  margin-left: 25%;
}
</style>
